package com.tilaiedu.mvc.controller;

import com.tilaiedu.mvc.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @Author xlzhang
 * @Date 2022/5/25 11:07
 * @Version 1.0
 * @Description TODO
 */
@Controller
public class UserController {

    // 当前是查询，表示只能功能get请求
    // http://localhost:8080/day03/users
    @GetMapping("/users")
    public String getUsers(){
        System.out.println("UserController.getUsers");
        return "success";
    }

    // http://localhost:8080/day03/user?id=1001  常规方式
    // http://localhost:8080/day03/user/1001   restFul
    // http://localhost:8080/day03/user/1001/books/5
    // @GetMapping("/user/{uid}/books/{bid}")
     @GetMapping("/user/{uid}")
    // 当使用restful风格后，参数必须使用@PathVariable
    public String getUserById(@PathVariable("uid") Integer uid){
        System.out.println("UserController.getUserById");
        System.out.println("id = " + uid);
        return "success";
    }

    // http://localhost:8080/day03/user
    @PostMapping("/user")
    public String addUser(User user){
        System.out.println("UserController.addUser");
        System.out.println("user = " + user);
        return "success";
    }

    // 修改操作
    // http://localhost:8080/day03/user/1001
    @PutMapping("/user/{uid}")
    public String updateUser(@PathVariable Integer uid, User user){
        System.out.println("UserController.updateUser");
        System.out.println("uid = " + uid);
        System.out.println("user = " + user);
        return "success";
    }

    // 删除操作
    // http://localhost:8080/day03/user/1001
    @DeleteMapping("/user/{uid}")
    public String deleteUser(@PathVariable Integer uid, User user){
        System.out.println("UserController.deleteUser");
        System.out.println("uid = " + uid);
        System.out.println("user = " + user);
        return "success";
    }

    // 删除操作
    // http://localhost:8080/day03/user/1,2,3,45
    @DeleteMapping("/users/{uid}")
    public String deleteUser(@PathVariable("uid") Integer[] uids){
        System.out.println("UserController.deleteUser");
        System.out.println("uids = " + Arrays.toString(uids));
        return "success";
    }
}











